package com.huangliusong.desigin.pattern.behavioral.interator;

/**
 * @author huangliusong
 * @since 2018/10/13
 * {@link }
 */
public class Test {
    public static void main(String[] args) {
        Course course1=new Course("课程1");
        Course course2=new Course("课程2");
        Course course3=new Course("课程3");
        Course course4=new Course("课程4");
        Course course5=new Course("课程5");
        Course course6=new Course("课程6");



        CourseAggregate courseAggregate=new CourseAggregateImpl();
        courseAggregate.addCourse(course1);
        courseAggregate.addCourse(course2);
        courseAggregate.addCourse(course3);
        courseAggregate.addCourse(course4);
        courseAggregate.addCourse(course5);
        courseAggregate.addCourse(course6);


        System.out.println("------------list----------");
        printCourses(courseAggregate);


        courseAggregate.removeCourse(course1);
        System.out.println("delete list------------");
        printCourses(courseAggregate);
    }

    public static void printCourses(CourseAggregate courseAggregate){
        CourseIterator courseIterator=courseAggregate.getCourseIterator();
        while (!courseIterator.isLastCourse()){
            Course course=courseIterator.nextCourse();
            System.out.println(course.getName());
        }
    }
}
